package pers.mor.tomcat.test;

import pers.mor.tomcat.http.Request;
import pers.mor.tomcat.http.Response;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 没有 Tomcat 类加载器体系中的 WebClassLoader
 * 无法加载 webapps 目录中各个项目的类
 * 暂时假设这个类就是webapps目录中b应用的servlet类
 */
public class HelloServlet extends HttpServlet {

    public HelloServlet(){
        System.out.println(this + " 的构造方法");
    }

    @Override
    public void init(ServletConfig config){
        String author = config.getInitParameter("author");
        String gender = config.getInitParameter("gender");

        System.out.println(this + " 的初始化方法 init");
        System.out.println("author = " + author);
        System.out.println("gender = " + gender);
    }


    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        Request request = (Request)req;
        Response response = (Response)resp;

        String respText = "假设这个类就是webapps目录中b应用的servlet类";

        response.setContentType("text/html");
        response.getWriter().print(respText);
    }
}
